{% extends 'inventory/base.html' %}

{% block title %}分类管理 - {{ block.super }}{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3">
                    <div>
                        <h2 class="card-title mb-0">分类列表</h2>
                        <p class="text-muted mb-md-0">管理所有商品分类信息</p>
                    </div>
                    <div class="d-flex flex-wrap gap-2">
                        <a href="{% url 'category_create' %}" class="btn btn-primary">
                            <i class="bi bi-plus-circle me-1"></i> 添加分类
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <div class="table-responsive table-container">
                    <table class="table table-striped table-hover align-middle">
                        <thead>
                            <tr>
                                <th>分类名称</th>
                                <th class="d-none d-md-table-cell">描述</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for category in categories %}
                            <tr>
                                <td>
                                    <h6 class="mb-0">{{ category.name }}</h6>
                                </td>
                                <td class="d-none d-md-table-cell">{{ category.description|truncatewords:10 }}</td>
                                <td>{{ category.created_at|date:"Y-m-d H:i" }}</td>
                                <td>
                                    <div class="btn-group">
                                        <a href="{% url 'category_edit' category.id %}" class="btn btn-sm btn-outline-primary">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <a href="{% url 'category_delete' category.id %}" class="btn btn-sm btn-outline-danger">
                                            <i class="bi bi-trash"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="4" class="text-center py-4">
                                    <div class="d-flex flex-column align-items-center">
                                        <i class="bi bi-inbox text-muted" style="font-size: 2rem;"></i>
                                        <p class="mt-2 mb-0">暂无分类数据</p>
                                        <small class="text-muted">点击"添加分类"按钮创建分类</small>
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}